Skip to content

Conversation

jwstolk
Copy link

@jwstolk jwstolk commented Aug 15, 2025

Fixes two crash paths in the new fuzz runner:

std/Build.Fuzz.addEntryPoint: guard pcs.len == 0 (avoid pcs[1..] slice panic) and make logs bounds-safe.

lib/fuzzer.zig:

appendSliceAssumeCapacity: early-return on zero-length and copy into [old_len .. old_len + items.len] to avoid forming a slice off a null base.

start(): ensure capacity before the first append when the corpus is empty (Web UI/coverage path triggers this).

minimal reproduction using zig master: zig init

// src/main.zig
const std = @import("std");
test "fuzz minimal" {
const Ctx = struct { fn testOne(_: @this(), input: []const u8) !void { _ = input; } };
try std.testing.fuzz(Ctx{}, Ctx.testOne, .{});
}

Run: zig build test --fuzz --webui=[::1]:45891.

Before: either a pcs slice panic or a segfault at the fuzzer memcpy (null-base slice).
After: fuzzing runs indefinitely (Ctrl-C to stop).

Note: the ensureTotalCapacity(len) is defensive; a higher-level invariant likely intended the assume-capacity precondition to hold. A TODO comment is left to flag follow-up.

…efore first append

- std/Build.Fuzz.addEntryPoint: guard pcs.len==0 and make logs bounds-safe.
- lib/fuzzer.zig:
  - appendSliceAssumeCapacity: early-return on zero-length; copy to [old_len .. old_len+len].
  - start(): ensureTotalCapacity before first append when corpus is empty (TODO: revisit invariant).
@ifreund
Copy link
Member

ifreund commented Aug 24, 2025

This isn't the correct fix or even in the correct direction, see #23423 for context.

@ifreund ifreund closed this Aug 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants